import {
  SET_START_TIME,
  SET_END_TIME,
  GET_DATA,
  GET_DATA_SUCCESS,
  GET_DATA_FAIL,
  SET_PAGE_NUM,
} from '@/actions/monthStatistics'
import util from '@/utils';

const initState = {
  endTime: null,
  pageNum: 1,
  pageSize: 10,
  startTime: null,
  loading: false,
  total: 0,
}

export default function monthStatisticsReducer(state = initState, action) {
  switch (action.type) {
    case SET_START_TIME:
      return { ...state, startTime: util.getStartTime(action.startTime) }
      break;

    case SET_END_TIME:
      return { ...state, endTime: util.getEndTime(action.endTime) }
      break;

    case GET_DATA:
      return { ...state, loading: true }
      break;

    case GET_DATA_SUCCESS:
      const { list, total } = action.data
      return { ...state, data: list, total, loading: false }
      break;

    case GET_DATA_FAIL:
      return { ...state, loading: false }
      break;

    case SET_PAGE_NUM:
      return { ...state, pageNum: action.pageNum }
      break;
  
    default:
      return state
      break;
  }
} 